﻿
namespace Songhay.Mvvm.Extensions
{
    using Models;

    /// <summary>
    /// Extensions of <see cref="ILightMessage"/>
    /// </summary>
    public static class ILightMessageExtensions
    {
        /// <summary>
        /// Determines whether message is expected.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="source">The source.</param>
        /// <returns>
        ///   <c>true</c> if message is expected; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsExpectedMessage(this ILightMessage message, LightMessageSource source)
        {
            if(message == null) return false;
            return (message.Source == source);
        }

        /// <summary>
        /// Determines whether message is expected.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="uniqueId">The unique id.</param>
        /// <returns>
        ///   <c>true</c> if message is expected; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsExpectedMessage(this ILightMessage message, string uniqueId)
        {
            if(message == null) return false;
            return (message.UniqueId == uniqueId);
        }

        /// <summary>
        /// Determines whether message is expected.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="source">The source.</param>
        /// <param name="uniqueId">The unique id.</param>
        /// <returns>
        ///   <c>true</c> if message is expected; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsExpectedMessage(this ILightMessage message, LightMessageSource source, string uniqueId)
        {
            return message.IsExpectedMessage(source) &&
                message.IsExpectedMessage(uniqueId);
        }
    }
}
